#include <stdio.h>

#include <iostream>
#include <string>

/**
 * \note Windows does not support russian language, sorry
 */

const char WORD_WORKER[] = "worker";
const char WORD_WARRIOR[] = "warrior";
const char WORD_RESEARCHER[] = "researcher";

const char WORD_WINGS[] = "wings";
const char WORD_WEAPON[] = "weapon";
const char WORD_STATE[] = "state";

#include "world/RobotsFactory.h"

IRobot &consturctionLoop()
{
    puts("Enter desired robot function:");
    printf("(Variants - \"%s\", \"%s\", \"%s\")\n", WORD_WORKER, WORD_WARRIOR, WORD_RESEARCHER);

    std::string choice;

    RobotsFactory factory;
    IRobot *robot = nullptr;
    do {
        std::cin >> choice;

        if (choice == WORD_WORKER)
        {
            robot = factory.createWorker();
        }
        else  if (choice == WORD_WARRIOR)
        {
            robot = factory.createWarrior();
        }
        else  if (choice == WORD_RESEARCHER)
        {
            robot = factory.createResearcher();
        }
        else
        {
            puts("Incorrect choice, try again.");
            printf("Enter \"%s\", \"%s\" or \"%s\"\n",
                   WORD_WORKER,
                   WORD_WARRIOR,
                   WORD_RESEARCHER);
        }
    } while (robot == nullptr);

    puts("Robot created and will greet you soon.");
    robot->sayMyName();

    return *robot;
}

void informationLoop(const IRobot &robot)
{
    std::string choice;

    puts("Now you can get more information about your robot.");
    puts("Enter stat name or \"exit\"");
    printf("Available commands: \"exit\", \"%s\", \"%s\", \"%s\":\n",
         WORD_WINGS,
         WORD_WEAPON,
         WORD_STATE);
    bool needExit = false;
    while (!needExit)
    {
        std::cin >> choice;
        if (choice == WORD_WINGS)
        {
            if (robot.hasWings())
                puts("Robot has wings");
            else
                puts("Robot has no wings");
        }
        else if (choice == WORD_WEAPON)
        {
            switch (robot.weapon())
            {
                case WeaponNone:
                    puts("Robot has no weapon");
                    break;
                case WeaponBlaster:
                    puts("Robot has blaster");
                    break;
                case WeaponRockets:
                    puts("Robot has rockets");
                    break;
            }
        }
        else if (choice == WORD_STATE)
        {
            switch (robot.weapon())
            {
                case MoveTypeGo:
                    puts("Robot moves usually");
                    break;
                case MoveTypeNone:
                    puts("Robot stays");
                    break;
                case MoveTypeRun:
                    puts("Robot runs");
                    break;
            }
        }
        else if (choice == "exit")
            needExit = true;
        else
        {
            printf("Incorrect command, variants: \"exit\", \"%s\", \"%s\", \"%s\":\n",
                 WORD_WINGS,
                 WORD_WEAPON,
                 WORD_STATE);
        }
    }
}

int main()
{
    IRobot &robot = consturctionLoop();
    informationLoop(robot);

    return 0;
}
